package Media;

import java.awt.Image;
import java.awt.Toolkit;
import java.awt.TrayIcon.MessageType;
import java.io.File;
import java.net.MalformedURLException;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

public class MediaController
{
    public static ImageIcon createImageIcon(String path)
    {
        File imageFile = new File(path);
        Image icon = null;

        try
        {
            icon = Toolkit.getDefaultToolkit().getImage(imageFile.toURI().toURL());
        }
        catch (MalformedURLException ex)
        {
            //Do nothing...
        }

        if (icon != null)
            return new ImageIcon(icon);
        else
        {
            System.err.println("A imagem não pode ser encontrada no diretorio: " + path);
            return null;
        }
    }

    public static void showErrorMessage(String message, String errorTitle)
    {
        ImageIcon image = createImageIcon("Imagens/Error.png");
        
        if(image != null)
            JOptionPane.showMessageDialog(null, message, errorTitle, MessageType.ERROR.ordinal(), MediaController.createImageIcon("Imagens/Error.png"));
        else
            JOptionPane.showMessageDialog(null, message, errorTitle, MessageType.ERROR.ordinal());
    }
}
